class Attachment < ActiveRecord::Base
  belongs_to :attachee, :polymorphic => true
  belongs_to :attachable, :polymorphic => true
  
  ATTACHABLE_TYPES = %w(
    PhotoSet
    Goal
  )
  
  def self.attach(attachee, attachable)
    attachment = 
      Attachment.find(
        :first,
        :conditions => {
          :attachee_id      => attachee.id,
          :attachee_type    => attachee.class.to_s,
          :attachable_id    => attachable.id,
          :attachable_type  => attachable.class.to_s
        })
  
    # Create new if it doesn't exist already.
    Attachment.new(
      :attachee => attachee,
      :attachable => attachable
    ).save if !attachment
  end
end
